﻿

using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cofe.Core.Implements;
using Cofe.Core.Interfaces;
using Cofe.Core.Logger;
using Cofe.Core.Utils;

namespace Cofe.Core.Entry
{
    [Export(typeof(ICofeService))]
    [ServicePriority(ServicePriorityAttribute.DefaultPriority_COFE)]
    public class EntryListVolumeFactory : IVolumeFactory
    {
        #region Methods

        public Task<IVolume> ConstructAsync(IVolumeRegistrar volumeRegistrar, string volumeId, string paramString)
        {
            var volumeInfo = new VolumeInfo() { FactoryId = FactoryId, ParamString = paramString, VolumeId = volumeId };

            var rootEntryList = CofeServices.EntryListRegistrar.CreateCustomEntryList(volumeId, true)
                .Properties.PrimaryPropertyProviderChecked;
            var eventSource = new ManualCofeSystemEventSource(volumeInfo);
            IVolume result = new Volume(volumeInfo, ParamParser,
                new EntryListDirectoryLister(rootEntryList) { ManualEventSource = eventSource
                     }, eventSource);
            
            return Task.FromResult<IVolume>(result);
        }
        #endregion

        #region Data
        private IEventHub _eventHub = null;
        private IParamParser _paramParser = new ParamParser();

        #endregion


        #region Public Properties

        public IEventHub EventHub
        {
            get { return _eventHub ?? CofeServices.ServiceLocater.FindService<IEventHub>(); }
            set { _eventHub = value; }
        }

        public IParamParser ParamParser
        {
            get { return _paramParser ?? CofeServices.ServiceLocater.FindService<IParamParser>(); }
            set { _paramParser = value; }
        }


        public string FactoryId
        {
            get { return "EntryList"; }
        }


        #endregion
    }
}
